const Schema = require("async-validator")
const {send} = require("@/zy-common/utils")


const verifyParams = (descriptor = {}) => {
  const validator = new Schema.default(descriptor)
  
  return async (ctx,next) => {
    const params = {...ctx.request.body,...ctx.request.params,...ctx.request.query}
    console.log("中间件验证参数",params);
    try {
      await validator.validate(params)
      await next()
    } catch (error) {
      send(ctx,200,'-1',error.errors?.[0].message)
    }
  }
}




module.exports = {
  verifyParams
}